<HTML><HEAD><TITLE>socket(+Domain, +Type, ?Stream)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">Stream I/O</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>socket(+Domain, +Type, ?Stream)</H1>
Creates a socket of a given type and domain and associates a stream with
it.


<DL>
<DT><EM>Domain</EM></DT>
<DD>Atom
</DD>
<DT><EM>Type</EM></DT>
<DD>Atom
</DD>
<DT><EM>Stream</EM></DT>
<DD>Atom, structure or variable.
</DD>
</DL>
<H2>Description</H2>
   socket/3 is a direct link to the socket(2) system call, available on
   Berkeley systems.  Domain is either unix or internet, type is stream or
   datagram.  It creates a socket of the given type in the given domain and
   creates a stream associated with it.  After the connection is
   established using bind/2, connect/2, listen/2 and/or accept/3, the
   stream can be used for input and output to communicate with other
   processes.

<P>
   The unix domain can be used for communication between processes on the
   same machine, whereas the internet domain can connect any two machines.
   The stream type supports point-to-point reliable communication, whereas
   the datagram communication is a network-type communication with clear
   message boundaries, which, however, are not visible in ECLiPSe .

<P>
   Note that in order to read data using read/1,2, it must have been
   written in Prolog term format (i.e.  ended with a period and a blank
   space character).  The output to sockets is buffered, so that data might
   be actually written only after a call to flush(Stream).

<P>
   When instantiated, Stream must be the symbolic stream name (atom).  The
   stream can also be specified as sigio(Stream).  In this case the socket
   is created and in addition it is instructed to send the signal io each
   time new data appears in it.

<P>

<H3>Modes and Determinism</H3><UL>
<LI>socket(+, +, -) is det
<LI>socket(+, +, +) is det
</UL>
<H3>Exceptions</H3>
<DL>
<DT><EM>(5) type error </EM>
<DD>Stream is instantiated, but not to an atom or a sigio    structure.
<DT><EM>(5) type error </EM>
<DD>Domain or Type are instantiated but not to atoms.
<DT><EM>(6) out of range </EM>
<DD>Domain or Type are atoms, but different from the accepted    ones.
<DT><EM>(170) system interface error </EM>
<DD>It was not possible to create the socket.
</DL>
<H2>Examples</H2>
<PRE>
Success:
      socket(unix, stream, s).
      socket(internet, datagram, socket).

Error:
      socket(unix, stream, 1)       (Error 5).
      socket(telnet, datagram, X)   (Error 6).



</PRE>
<H2>See Also</H2>
<A HREF="../../kernel/iostream/bind-2.html">bind / 2</A>, <A HREF="../../kernel/iostream/listen-2.html">listen / 2</A>, <A HREF="../../kernel/iostream/accept-3.html">accept / 3</A>, <A HREF="../../kernel/iostream/connect-2.html">connect / 2</A>, <A HREF="../../kernel/iostream/new_socket_server-3.html">new_socket_server / 3</A>, <A HREF="../../kernel/iostream/pipe-2.html">pipe / 2</A>, <A HREF="../../kernel/opsys/exec-2.html">exec / 2</A>
</BODY></HTML>
